Images in XML sitemap are always linked to base store in multistore on Schedule#19598
Images in XML sitemap are always linked to base store in multistore on Schedule#19598magento-engcom-team merged 9 commits intomagento:2.3-developfrom Nazar65:issue-19596
Conversation
|
Hi @Nazar65. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
sivaschenko
left a comment
There was a problem hiding this comment.
@Nazar65 thanks for the contribution. Please see the code review notes.
| /** | ||
| * @var \Magento\Store\Model\App\Emulation $appEmulation | ||
| */ | ||
| protected $appEmulation; |
There was a problem hiding this comment.
please change the access level to private
| * @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation | ||
| */ | ||
| public function __construct( | ||
| Emulation $appEmulation = null, |
There was a problem hiding this comment.
Please add move the new parameter to the last position in the parameters list
|
@sivaschenko all done. |
sivaschenko
left a comment
There was a problem hiding this comment.
@Nazar65 thanks for your updates, please see remaining review notes
| \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, | ||
| \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation | ||
| \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation, | ||
| Emulation $appEmulation |
There was a problem hiding this comment.
This new parameter should be optional
There was a problem hiding this comment.
Same here if i add optional, as this have been in older commit the codeMess test will fail.
Backward Compatibility Policy is not applied to Plugins, Observers and Setup Scripts.
There was a problem hiding this comment.
The class Observer has a coupling between objects value of 13.
| try { | ||
| $this->appEmulation->startEnvironmentEmulation( | ||
| $sitemap->getStoreId(), | ||
| 'frontend', |
There was a problem hiding this comment.
This Class have many dependency, so if i will use constant the codeMess test will fail.
There was a problem hiding this comment.
In this case it's better to decompose the class in favour to dropping constant usage
Co-Authored-By: Nazar65 <nazarn96@gmail.com>
|
@sivaschenko please look at comments. |
|
Hi @Nazar65 , I think the best way to resolve the problems with static tests and keep the good code style and backward compatibility - is extracting all the business logic to a model from the observer. Actually, this observer is a very good candidate for refactoring. Could you extract it? |
|
@sivaschenko yes i agree with you. I'm will work on this :) |
# Conflicts: # app/code/Magento/Sitemap/Model/Observer.php
|
Hi @sivaschenko can you please look at newly commit ? |
sivaschenko
left a comment
There was a problem hiding this comment.
Hi @Nazar65 , thanks for your refactoring! It looks great, however, I have some imporvement suggestions. Please see my code review notes.
| */ | ||
| const XML_PATH_CRON_EXPR = 'crontab/default/jobs/generate_sitemaps/schedule/cron_expr'; | ||
|
|
||
| /** |
There was a problem hiding this comment.
Please keep all existing constants in the Observer as they could be already used by third-party extensions.
| * @var \Magento\Store\Model\StoreManagerInterface | ||
| */ | ||
| protected $_transportBuilder; | ||
| protected $_storeManager; |
There was a problem hiding this comment.
I'd change all properties to private and remove the "_" prefix (for consistency and to be compatible with PSR)
| $transport->sendMessage(); | ||
|
|
||
| $this->inlineTranslation->resume(); | ||
| $this->sitemapEmail->sendErrorEmail($errors); |
There was a problem hiding this comment.
Please call this method after the foreach (as all the errors have to be accumulated in $errors first)
| self::XML_PATH_ERROR_RECIPIENT, | ||
| ScopeInterface::SCOPE_STORE | ||
| ); | ||
| if ($errors && $recipient) { |
There was a problem hiding this comment.
I'd move this condition to the observer or to a separate method, to keep this method solid
| * | ||
| * @var \Magento\Framework\App\Config\ScopeConfigInterface | ||
| */ | ||
| private $_scopeConfig; |
There was a problem hiding this comment.
Property should not be prefixed with a single underscore, see https://www.php-fig.org/psr/psr-2/#42-properties
| @@ -0,0 +1,109 @@ | |||
| <?php | |||
There was a problem hiding this comment.
Please use strict mode in for all new PHP files
| \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation | ||
| ScopeConfigInterface $scopeConfig, | ||
| CollectionFactory $collectionFactory, | ||
| StoreManagerInterface $storeManager, |
There was a problem hiding this comment.
Neither of two classes appears to be using store manager, so I think this dependency can be removed from both of them
| if ($errors && $recipient) { | ||
| $this->inlineTranslation->suspend(); | ||
|
|
||
| $this->_transportBuilder->setTemplateIdentifier( |
There was a problem hiding this comment.
I think it may be beneficial to wrap the email send operation in a try-catch block to gracefully handle situations when a mail server is not responsive.
There is an example here
magento2/app/code/Magento/Contact/Model/Mail.php
Lines 68 to 87 in f77f96b
However, I would improve the approach by catching an exception and writing it to an exception log
| /** | ||
| * Sends emails for the scheduled generation of the sitemap file | ||
| */ | ||
| class SitemapSendEmail |
There was a problem hiding this comment.
I'd rename the class to the something like EmailNotification or Mail and the method to send or sendErrors to avoid duplicate wording in full method reference. Currently it's Magento\Sitemap\Model\SitemapSendEmail::sendErrorEmail
|
Hi @sivaschenko all done. :) |
sivaschenko
left a comment
There was a problem hiding this comment.
Hi @Nazar65 thanks for the refactoring! I've added some code suggestions. You can simply add all my suggestions to batch and commit them.
|
@sivaschenko all done, thank you for the review :) |
|
Thank you @Nazar65 finally there are currently 14 commits, would you like to squash them into a single one? |
|
@sivaschenko sorry for that, now i "squash" to one commit. |
|
Hi @sivaschenko, thank you for the review. |
|
@sivaschenko @sidolov so do I change the variables again? |
|
Hi @sidolov, thank you for the review. |
|
HI @sivaschenko @sidolov any updates ? |
|
Hi @Nazar65 the pull request is in queue for delivery to mainline |
|
Hi @Nazar65, thank you for your contribution! |
… multistore on Schedule #19598
Description (*)
Images in XML sitemap are always linked to base store in multistore on Schedule
Fixed Issues (if relevant)
Manual testing scenarios (*)
Website URL 1: https://my_website.com
Website URL 2: https://my_website.co.uk
Got to Stores->Configuration->Catalog->XML Sitemap->General Settings:
2.Set to Enable, Start Time, Frequency Daily etc...
TIP: I've set to a few minutes before checking!
Website 1 should have images url referencing Website 1 domain = https://my_website.com
Contribution checklist (*)